﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Data;

namespace BBS.Data.Forum
{
    public class BoardTable
    {
        private static string _connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        private BaseTable _table = new BaseTable(_connstr, "Board");

        public DataTable GetAll()
        {
            return _table.SelectTable();
        }

        public int Insert(BBS.Entity.Board board)
        {
            string sql = "insert into [board] (title,status,information,parent_id,order_number) values (@title,@status,@information,@parent_id,@order_number)";
            return _table.ExecuteNonQuery(sql, new OleDbParameter("title", board.Title),
                                          new OleDbParameter("status", board.Status),
                                          new OleDbParameter("information", board.Information),
                                          new OleDbParameter("parent_id", board.ParentId),
                                          new OleDbParameter("order_number", board.Order));
        }

        public int Update(BBS.Entity.Board board)
        {
            string sql = "update [board] set title=@title,status=@status,information=@information,parent_id=@parent_id,order_number=@order_number where id = @id";
            return _table.ExecuteNonQuery(sql, new OleDbParameter("title", board.Title),
                                          new OleDbParameter("status", board.Status),
                                          new OleDbParameter("information", board.Information),
                                          new OleDbParameter("parent_id", board.ParentId),
                                          new OleDbParameter("order_number", board.Order),
                                          new OleDbParameter("id", board.Id));
        }
    }
}
